package com.centronix.manager.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centronix.bean.ComboBean;
import com.centronix.dao.EmployeeDAO;
import com.centronix.domain.Employee;
import com.centronix.manager.EmployeeManager;

@Service(value="employeeManager")
@Transactional
public class EmployeeManagerImpl implements EmployeeManager {
	
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private EmployeeDAO employeeDAO;

	public List<Employee> getAllEmployees(){
		return employeeDAO.findAll();
	}
	
	
	public List<ComboBean> getEmployeeCombo(){
		List<ComboBean> comboBeans = new ArrayList<>();
		comboBeans.add(ComboBean.getDefaultCombo());
		List<Employee> employees= employeeDAO.findAll();
		ComboBean comboBean = null;
		for (Employee employee : employees) {
			comboBean = new ComboBean();
			copyEmployeeToComboBean(employee, comboBean);
			comboBeans.add(comboBean);
		}
		return comboBeans;
	}
	
	public void copyEmployeeToComboBean(final Employee employee, final ComboBean comboBean) {
		comboBean.setValue(String.valueOf(employee.getEmpId()));
		comboBean.setLabel(employee.getPerson().getName());
	}
	
	public EmployeeDAO getEmployeeDAO() {
		return employeeDAO;
	}

	public void setEmployeeDAO(EmployeeDAO employeeDAO) {
		this.employeeDAO = employeeDAO;
	}
	
}
